package com.qianchang.microfinance.view.credit.data;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.dm.library.utils.ViewUtils;
import com.qianchang.microfinance.R;
import com.qianchang.microfinance.bean.DataInfoBean;
import com.dm.library.adapter.CommonAdapter;
import com.dm.library.adapter.CommonViewHolder;
import com.dm.library.widgets.OneLineLinearLayout;
import com.qianchang.microfinance.bean.FindUserBasicInfoBean;
import com.qianchang.microfinance.utils.StringReplaceUtil;

import java.util.List;

import static com.qianchang.microfinance.utils.StringReplaceUtil.replaceNameTostar;


/**
 * 版 权: 深圳市迪蒙网络科技有限公司
 * 描 述:
 * 修 改 人: zhoulai
 * 修改时间: 2017/7/10 19:12
 */


public class DataInfoAdapter extends CommonAdapter<DataInfoBean> {

    private FindUserBasicInfoBean findUserBasicInfoBean;


    public DataInfoAdapter(Context mContext, List<DataInfoBean> beanList) {
        super(mContext, beanList, R.layout.adapter_data_info);
    }


    public void setFindUserBasicInfoBean(FindUserBasicInfoBean mFindUserBasicInfoBean){
        this.findUserBasicInfoBean = mFindUserBasicInfoBean;
        notifyDataSetChanged();
    }


    @Override
    protected void convert(CommonViewHolder holder, DataInfoBean dataInfoBean, int position) {
        OneLineLinearLayout lllMyData = holder.getView(R.id.ll_my_data);
        TextView textView = holder.getView(R.id.text_id);
        String statusString = null;
        int color = R.color.common_black_color_9;
        switch (dataInfoBean.getStatus()) {
            case MyDataStatus.QRZ:
                color = R.color.common_blue_color;
                if(dataInfoBean.isNeedCommit()){
                    statusString = mContext.getString(R.string.never_submit);
                }else{
                    statusString = mContext.getString(R.string.never_checked);
                }
                break;
            case MyDataStatus.YTJ:
                color = R.color.common_black_color_9;
                if(dataInfoBean.isNeedCommit()){
                    statusString = mContext.getString(R.string.has_submit);
                }else{
                    statusString = mContext.getString(R.string.has_checked);
                }
                break;
            case 2:
                color = R.color.common_black_color_9;
                if(dataInfoBean.isNeedCommit()){
                    statusString = mContext.getString(R.string.never_checked_certification);
                }else{
                    statusString = mContext.getString(R.string.never_checked_certification);
                }
                break;
            case 3:
                color = R.color.common_black_color_9;
                if(dataInfoBean.isNeedCommit()){
                    statusString = "未认证 ";
                }else{
                    statusString = "未认证 ";
                }
                break;
            case 4:
                color = R.color.common_black_color_9;
                if(dataInfoBean.isNeedCommit()){
                    statusString = "审核中 ";
                }else{
                    statusString = "审核中 ";
                }
                break;
            default:
                color = R.color.common_blue_color;
                if(dataInfoBean.isNeedCommit()){
                    statusString = mContext.getString(R.string.never_submit);
                }else{
                    statusString = mContext.getString(R.string.never_checked);
                }
                break;
        }
        lllMyData.setRightTextColor(color);
        lllMyData.setLeftContent(dataInfoBean.getTitle());
        lllMyData.setRightContent(statusString);

        switch (position){
            case 0:                                     //实名验证
                String status = lllMyData.getRightText().toString();
                if(status.equals("已认证")){
                    textView.setVisibility(View.VISIBLE);
                    if(findUserBasicInfoBean != null){
                        String realName = findUserBasicInfoBean.getRealName();
                        realName = replaceNameTostar(realName);
                        textView.setText(realName);
                    }
                }else{
                    textView.setVisibility(View.GONE);
                }
                break;
            case 1:
                textView.setVisibility(View.GONE);
                break;
            case 2:
                textView.setVisibility(View.GONE);
                break;
            case 3:                                 //手机验证
                textView.setVisibility(View.VISIBLE);
                String phonestatus = lllMyData.getRightText().toString();
                if(phonestatus.equals("已认证")){
                    if(findUserBasicInfoBean != null){
                        String phone = findUserBasicInfoBean.getPhone();
                        textView.setText(ViewUtils.formatPhone(phone));
                    }else{
                        textView.setVisibility(View.GONE);
                    }
                }else{
                    textView.setVisibility(View.GONE);
                }
                break;
            case 4:                                 //银行卡信息
                textView.setVisibility(View.GONE);
                String bankstatus = lllMyData.getRightText().toString();
                if(bankstatus.equals("已认证")){
                    if(findUserBasicInfoBean != null){
                        String bankAlias = findUserBasicInfoBean.getBankAlias();
                        if(bankAlias != null && !(bankAlias.equals(""))){
                            String[] str = bankAlias.split("·");
                            String bStr = "";
                            if(str.length > 0){
                                bStr = str[0];
                            }
                            String bankNub = "";
                            if(str.length > 1){
                                bankNub = str[1];
                                bankNub = bankNub.substring(bankNub.length()-6,bankNub.length());
                            }
                            textView.setText(bStr + bankNub);
                            textView.setVisibility(View.VISIBLE);
                        }else {
                            textView.setVisibility(View.GONE);
                        }
                    }else{
                        textView.setVisibility(View.GONE);
                    }
                }else {
                    textView.setVisibility(View.GONE);
                }
                break;
            case 5:
                textView.setVisibility(View.GONE);
                break;
            case 6:
                textView.setVisibility(View.GONE);
                break;
            case 7:
                textView.setVisibility(View.GONE);
                break;
            case 8:
                textView.setVisibility(View.GONE);
                lllMyData.setRightContent("");
                break;
            default:
                textView.setVisibility(View.GONE);
                break;
        }

    }
}
